#include "../inc/texture.h"
#include "../inc/init.h"
#include <SDL_image.h>

SDL_Texture *gTexture = NULL;

SDL_Texture* loadTexture(const char* imgPath){
    SDL_Texture *texture = NULL;
    SDL_Surface *surface = IMG_Load(imgPath);
    if(!surface){
        printf("Failed to load image %s: %s", imgPath, IMG_GetError());
    }else{
        texture = SDL_CreateTextureFromSurface(gRender, surface);
        if(!texture){
            printf("Failed to load image %s: %s", imgPath, SDL_GetError());
        }
        SDL_FreeSurface(surface);
    }
    return texture;
}

SDL_Texture* loadTextureEx(const char* imgPath, SDL_Renderer **renderer){
    SDL_Texture *texture = NULL;
    SDL_Surface *surface = IMG_Load(imgPath);
    if(!surface){
        printf("Failed to load image %s: %s", imgPath, IMG_GetError());
    }else{
        texture = SDL_CreateTextureFromSurface(*renderer, surface);
        if(!texture){
            printf("Failed to load image %s: %s", imgPath, SDL_GetError());
        }
        SDL_FreeSurface(surface);
    }
    return texture;
}

